﻿Option Infer On
Imports System
Imports System.IO
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation
Imports ChatEngine.Client, Microsoft.VisualBasic
Partial Public Class ChanCenter
    Dim CEInst As IRCClient
    Dim a As String()
    Dim B, ChanVar As String
    Delegate Sub Nav(ByVal E As ChatEngine.Connections.BanListArgs)
#Region " Buttons"
    Private Sub Close_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles CloseButton.MouseDown
        Dim ISC As New ImageSourceConverter
        CloseButton.Source = ISC.ConvertFrom("pack://application:,,,/Images/Close-pressed.png")
    End Sub
    Private Sub Close_MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles CloseButton.MouseEnter
        Dim ISC As New ImageSourceConverter
        CloseButton.Source = ISC.ConvertFrom("pack://application:,,,/Images/close-hover.png")
    End Sub
    Private Sub Close_MouseLeave(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles CloseButton.MouseLeave
        Dim ISC As New ImageSourceConverter
        CloseButton.Source = ISC.ConvertFrom("pack://application:,,,/Images/close.png")
    End Sub
    Private Sub Close_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles CloseButton.MouseUp
        Dim ISC As New ImageSourceConverter
        CloseButton.Source = ISC.ConvertFrom("pack://application:,,,/Images/close.png")
        Me.Close()
        GC.Collect()
    End Sub
    Private Sub Max_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Max.MouseDown
        Dim ISC As New ImageSourceConverter
        Max.Source = ISC.ConvertFrom("pack://application:,,,/Images/Maximize-pressed.png")
    End Sub
    Private Sub Max_MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles Max.MouseEnter
        Dim ISC As New ImageSourceConverter
        Max.Source = ISC.ConvertFrom("pack://application:,,,/Images/Maximize-hover.png")
    End Sub
    Private Sub Max_MouseLeave(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles Max.MouseLeave
        Dim ISC As New ImageSourceConverter
        Max.Source = ISC.ConvertFrom("pack://application:,,,/Images/Maximize.png")
    End Sub
    Private Sub Max_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Max.MouseUp
        Dim ISC As New ImageSourceConverter
        Min.Source = ISC.ConvertFrom("pack://application:,,,/Images/Minimize.png")
        If Me.WindowState <> Windows.WindowState.Maximized Then
            Me.WindowState = Windows.WindowState.Maximized
        Else
            Me.WindowState = Windows.WindowState.Normal
        End If
    End Sub
    Private Sub Min_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Min.MouseDown
        Dim ISC As New ImageSourceConverter
        Min.Source = ISC.ConvertFrom("pack://application:,,,/Images/Minimize-pressed.png")
    End Sub
    Private Sub Min_MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles Min.MouseEnter
        Dim ISC As New ImageSourceConverter
        Min.Source = ISC.ConvertFrom("pack://application:,,,/Images/Minimize-hover.png")
    End Sub
    Private Sub Min_MouseLeave(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles Min.MouseLeave
        Dim ISC As New ImageSourceConverter
        Min.Source = ISC.ConvertFrom("pack://application:,,,/Images/Minimize.png")
    End Sub
    Private Sub Min_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Min.MouseUp
        Dim ISC As New ImageSourceConverter
        Min.Source = ISC.ConvertFrom("pack://application:,,,/Images/Minimize.png")
        Me.WindowState = Windows.WindowState.Minimized
    End Sub
#End Region
    Public Property ChatEngInst() As IRCClient
        Get
            Return CEInst
        End Get
        Set(ByVal value As IRCClient)
            CEInst = value
        End Set
    End Property
    Public Property ChannelName() As String
        Get
            Return ChanVar
        End Get
        Set(ByVal value As String)
            ChanVar = value
        End Set
    End Property
    Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
    End Sub
    Public Sub LoadBanList(ByVal E As ChatEngine.Connections.BanListArgs)
        Me.Dispatcher.BeginInvoke(Windows.Threading.DispatcherPriority.ApplicationIdle, New Nav(AddressOf LoadList), E)
    End Sub
    Private Sub LoadList(ByVal E As ChatEngine.Connections.BanListArgs)
        Dim lbItem As ListBoxItem
        If Not IsNothing(E.BanList) Then
            For Each Item As ChatEngine.Client.Channel.BanListItem In E.BanList
                lbItem = New ListBoxItem
                lbItem.Style = DirectCast(Me.Resources("WhiteFG"), Style)
                lbItem.Content = Item.HostMask & " " & Item.BannedBy
                BanListBox.Items.Add(lbItem)
            Next
        End If
    End Sub
    Private Sub ChanCenter_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        AddHandler ChatEngInst.BanListRecvd, AddressOf LoadBanList
    End Sub
    Private Sub BanListBox_GotFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles BanListBox.GotFocus
        RemoveBan.IsEnabled = True
    End Sub
    Private Sub BanListBox_LostFocus(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles BanListBox.LostFocus
        '   RemoveBan.IsEnabled = False
    End Sub
    Private Sub RemoveBan_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles RemoveBan.Click
        If Not IsNothing(BanListBox.SelectedItem) Then
            B = CType(BanListBox.SelectedItem, ListBoxItem).Content
            a = B.Split(New Char() {" "})
            ChatEngInst.RawCommand("MODE " & ChannelName & " -b " & a(0))
            Dim lbitem = From lbfind As ListBoxItem In BanListBox.Items Where lbfind.Content.ToString Like B
            If Not IsNothing(lbitem(0)) Then BanListBox.Items.Remove(lbitem(0))
        End If
    End Sub
    Private Sub OKButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles OKButton.Click
        If oost.IsChecked Then
            ChatEngInst.RawCommand("MODE +t")
        End If
    End Sub
End Class